package com.parleys.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.parleys.R;
import com.parleys.domain.ParleysListObject;

public class ModeSelectionListAdapter extends ParleysListAdapter {

	public ModeSelectionListAdapter(Context context, List<? extends ParleysListObject> data) {
		super(context, data, null, null);
	}

	public View getView(final int position, final View convertedView, final ViewGroup parent) {

		View view = null;

		if (convertedView == null) {
			LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = vi.inflate(R.layout.list_element, null);
			ViewWrapper viewWrapper = new ViewWrapper(view);
			view.setTag(viewWrapper);
		} else {
			view = convertedView;
		}

		final ParleysListObject parleysObject = data.get(position);
		if (parleysObject != null) {

			final ViewWrapper viewWrapper = (ViewWrapper) view.getTag();
			viewWrapper.getText1().setText(parleysObject.getName());
			viewWrapper.getText2().setText(parleysObject.getDescription());
			if (context.getString(R.string.online).equals(parleysObject.getThumbnail())) {
				viewWrapper.getImageView().setImageResource(R.drawable.earth);
			} else {
				viewWrapper.getImageView().setImageResource(R.drawable.hdd);
			}
		}

		return view;
	}
}
